let app = getApp();
import { getShop } from "../../request/api";
let iconUrl = 'https://atush.vip/static/icons/';

Component({

    /**
     * 组件的属性列表
     */
    properties: {
      freshIsPulldown: {
        type: Boolean,
        value: false,
        observer: "onPullDownMethod"
      },

      onReachBottomCount: {
          type: Number,
          value: 1,
          observer: "onBottomMethod",
      }
    },

    /**
     * 组件的初始数据
     */
    data: {
      lang: null,
      filter_hidden_box: false,
      filter_hidden_box_animation: false,
      box: [],
      filterShop: [
        {id: 1, name: 'dinningRoom', icon: iconUrl +'canting.svg'},
        {id: 2, name: 'supermarket', icon: iconUrl +'chaoshi.svg'},
        {id: 3, name: 'dessert', icon: iconUrl +'tianping.svg'},
        {id: 4, name: 'clothing', icon: iconUrl +'fuzhuang.svg'},
        {id: 5, name: 'hotPot', icon: iconUrl +'huoguo.svg'},
        {id: 6, name: 'repair', icon: iconUrl +'weixiu.svg'},
        {id: 7, name: 'billiards', icon: iconUrl +'billiards.svg'},
        {id: 8, name: 'all', icon: iconUrl + 'quanbu.svg'},
      ],
      filterShop_all: [
        {id: 1, name: 'dinningRoom', icon: iconUrl +'canting.svg'},
        {id: 2, name: 'supermarket', icon: iconUrl +'chaoshi.svg'},
        {id: 3, name: 'dessert', icon: iconUrl +'tianping.svg'},
        {id: 4, name: 'clothing', icon: iconUrl +'fuzhuang.svg'},
        {id: 5, name: 'altun', icon: iconUrl +'goldShop.svg'},
        {id: 6, name: 'hotPot', icon: iconUrl +'huoguo.svg'},
        {id: 7, name: 'repair', icon: iconUrl +'weixiu.svg'},
        {id: 8, name: 'billiards', icon: iconUrl +'billiards.svg'},
        {id: 9, name: 'flowers', icon: iconUrl +'flowers.svg'},
        {id: 10, name: 'makeup', icon: iconUrl +'makeup.svg'},
        {id: 11, name: 'photography', icon: iconUrl +'photography.svg'},
        {id: 12, name: 'xiche', icon: iconUrl +'xiche.svg'},
        {id: 13, name: 'haircut', icon: iconUrl +'chuifengji.svg'},
        {id: 14, name: 'dujiacun', icon: iconUrl +'dujiacun.svg'},
        {id: 15, name: 'yangsheng', icon: iconUrl +'yangsheng.svg'},
        {id: 16, name: 'real_estate', icon: iconUrl +'yumilakOy.svg'},
      ],

      // 分页
      pageNo: 1,
      totalPage: 0,
    },

    /**
     * 组件的方法列表
     */
    methods: {
      
      // 筛选店铺
      onCilckShopFilter(item) {
        let filterId = item.currentTarget.dataset.item.id
        let filterType = null
        switch (filterId) {
          case 1:
              filterType = 25
              break;
          case 2:
              filterType = 26
              break;
          case 3:
              filterType = 27
              break;
          case 4:
              filterType = 28
              break;
          case 5:
              filterType = 37
              break;
          case 6:
              filterType = 38
              break;
          case 7:
              filterType = 39
              break;
          case 8:
              // 打开更多筛选店铺
              return this.shopMore()
          default:
              break;
        }
        wx.navigateTo({
            url: '/pages/home/shop/filterShop/filterShop?filterType=' + filterType
        });
      },

      // 从筛选全部店铺列表
      onCilckAllShopFilter(item) {
        let filterId = item.currentTarget.dataset.item.id
        let filterType = null
        switch (filterId) {
            case 1:
                filterType = 25
                break;
            case 2:
                filterType = 26
                break;
            case 3:
                filterType = 27
                break;
            case 4:
                filterType = 28
                break;
            case 5:
                filterType = 36
                break;
            case 6:
                filterType = 37
                break;
            case 7:
                filterType = 38
                break;
            case 8:
                filterType = 39
                break;
            case 9:
                filterType = 40
                break;
            case 10:
                filterType = 41
                break;
            case 11:
                filterType = 42
                break;
            case 12:
                filterType = 43
                break;
            case 13:
                filterType = 44
                break;
            case 14:
                filterType = 45
                break;
            case 15:
                filterType = 46
                break;
            case 16:
                filterType = 47
                break;
            default:
                break;
        }
        wx.navigateTo({
            url: '/pages/home/shop/filterShop/filterShop?filterType=' + filterType
        });
        let that = this;
        setTimeout(function() {
            that.setData({ filter_hidden_box_animation: true, filter_hidden_box: false })
        }, 2000)
      },

      // 灰色页面点击
      shopPageMask() {
        let that = this;
        this.setData({ filter_hidden_box_animation: true, filter_hidden_box: false })
        // setTimeout(function () {
            // that.setData({ filter_hidden_box: false })
        // }, 1000)
    },

    // 打开更多筛选店铺
    shopMore() {
        if(!this.data.filter_hidden_box) {
            this.setData({ filter_hidden_box: true, filter_hidden_box_animation: false })
        }
    },

    // 获取内容
    getPost() {
        let status = 1
        let data = { status, pageNo : this.data.pageNo }
        getShop(res => {
            if (res.statusCode == 200) {
                this.setData({ box: this.data.box.concat(res.data.data), totalPage : res.data.totalPage })
            }
        }, data);
    },

    // 往详细页面
    goDetailed(event) {
        let itemId = event.currentTarget.dataset.item.id
        wx.navigateTo({
            url: '/pages/home/shop/shopDetailed/shopDetailed?itemId=' + itemId
        });
    },

    /**
   * 页面上拉触底事件的处理函数
   */
  onPullDownMethod(value) {
    console.log(value);
    if (value == true) {
        this.noMoreMethod(true)
    }
  },
  onBottomMethod(number) {
      // console.log("load more: ", number, this.data.pageNo, this.data.totalPage);
      if (this.data.pageNo >= this.data.totalPage || this.data.totalPage == undefined) {
          // console.log("没有更多啦");
          return
      }
      this.setData({ pageNo: this.data.pageNo += 1})
      this.getPost()
  },

  },

  lifetimes: {
    attached: function () {
        this.setData({ lang: app.globalData.lang, navTitle: "shopInfo", navigation: true })
    },
    ready(){
        this.setData({isPageNo : true})
        this.getPost()
    },
  },

})